package sword.T54;

import util.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: 18362
 * @Create: 2022-04-10 0:34:53 星期日
 */

class Solution {

    private int res = 0;
    private boolean find = false;
    private int cur = 1;

    public int kthLargest(TreeNode root, int k) {
        inorder(root, k);
        return res;
    }

    private void inorder(TreeNode root, int k) {
        if (root == null || find)
            return;
        inorder(root.right, k);
        if (cur == k) {
            find = true;
            res = root.val;
        }
        cur++;
        inorder(root.left, k);
    }
}